@@ -22,16 +22,14 @@ import butterknife.ButterKnife; |
||
| 22 | 22 |
|
| 23 | 23 |
public class PhotoRecyclerAdapter extends RecyclerView.Adapter<PhotoRecyclerAdapter.MyViewHolder> {
|
| 24 | 24 |
|
| 25 |
- private Context context; |
|
| 26 | 25 |
private LayoutInflater mInflater; |
| 27 | 26 |
private ArrayList<PhotoBean> photoList; |
| 28 | 27 |
private int width; |
| 29 | 28 |
private DisplayImageOptions options; |
| 30 | 29 |
|
| 31 | 30 |
public PhotoRecyclerAdapter(Context context){
|
| 32 |
- this.context = context; |
|
| 33 |
- width = DeviceUtils.getScreenWidth(this.context); |
|
| 34 |
- mInflater = LayoutInflater.from(this.context); |
|
| 31 |
+ width = DeviceUtils.getScreenWidth(context); |
|
| 32 |
+ mInflater = LayoutInflater.from(context); |
|
| 35 | 33 |
options = ImageLoaderUtils.getOptions(R.drawable.default_img); |
| 36 | 34 |
} |
| 37 | 35 |
|
@@ -45,21 +43,12 @@ public class PhotoRecyclerAdapter extends RecyclerView.Adapter<PhotoRecyclerAdap |
||
| 45 | 43 |
} |
| 46 | 44 |
} |
| 47 | 45 |
|
| 48 |
- public synchronized void addPhotoBeans(ArrayList<PhotoBean> items){
|
|
| 49 |
- if(photoList==null){
|
|
| 50 |
- photoList = new ArrayList<>(); |
|
| 51 |
- } |
|
| 52 |
- for(int k = items.size()-1;k>=0;k--){
|
|
| 53 |
- if(!photoList.contains(items.get(k))){
|
|
| 54 |
- photoList.add(0,items.get(k)); |
|
| 55 |
- notifyItemInserted(0); |
|
| 56 |
- } |
|
| 46 |
+ public synchronized void removePhotoAtIndex(int index){
|
|
| 47 |
+ if(photoList==null || photoList.size()<=index){
|
|
| 48 |
+ return; |
|
| 57 | 49 |
} |
| 58 |
- } |
|
| 59 |
- |
|
| 60 |
- |
|
| 61 |
- public ArrayList<PhotoBean> getPhotoList(){
|
|
| 62 |
- return photoList; |
|
| 50 |
+ photoList.remove(index); |
|
| 51 |
+ notifyItemRemoved(index); |
|
| 63 | 52 |
} |
| 64 | 53 |
|
| 65 | 54 |
@Override |
@@ -5,6 +5,7 @@ import android.content.Intent; |
||
| 5 | 5 |
import android.os.Bundle; |
| 6 | 6 |
import android.support.v7.widget.LinearLayoutManager; |
| 7 | 7 |
import android.support.v7.widget.RecyclerView; |
| 8 |
+import android.support.v7.widget.helper.ItemTouchHelper; |
|
| 8 | 9 |
import android.view.View; |
| 9 | 10 |
import android.widget.TextView; |
| 10 | 11 |
import android.widget.Toast; |
@@ -29,6 +30,20 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
| 29 | 30 |
|
| 30 | 31 |
private static final int JOIN_REQUEST_CODE = 3002; |
| 31 | 32 |
|
| 33 |
+ private ItemTouchHelper.Callback mCallback = new ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP | ItemTouchHelper.DOWN, |
|
| 34 |
+ ItemTouchHelper.LEFT|ItemTouchHelper.RIGHT) {
|
|
| 35 |
+ @Override |
|
| 36 |
+ public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
|
|
| 37 |
+ return false; |
|
| 38 |
+ } |
|
| 39 |
+ |
|
| 40 |
+ @Override |
|
| 41 |
+ public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
|
|
| 42 |
+ int position = viewHolder.getAdapterPosition(); |
|
| 43 |
+ adapter.removePhotoAtIndex(position); |
|
| 44 |
+ } |
|
| 45 |
+ }; |
|
| 46 |
+ |
|
| 32 | 47 |
@Override |
| 33 | 48 |
protected void onCreate(Bundle savedInstanceState) {
|
| 34 | 49 |
super.onCreate(savedInstanceState); |
@@ -39,9 +54,14 @@ public class SessionActivity extends BaseActivity implements SessionContract.Vie |
||
| 39 | 54 |
|
| 40 | 55 |
titleTextView.setText(getString(R.string.scene)+sessionBean.sessionSeq); |
| 41 | 56 |
adapter = new PhotoRecyclerAdapter(this); |
| 57 |
+ |
|
| 42 | 58 |
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(this); |
| 43 | 59 |
photosRecyclerView.setLayoutManager(layoutManager); |
| 44 | 60 |
photosRecyclerView.setAdapter(adapter); |
| 61 |
+ |
|
| 62 |
+ ItemTouchHelper itemTouchHelper = new ItemTouchHelper(mCallback); |
|
| 63 |
+ itemTouchHelper.attachToRecyclerView(photosRecyclerView); |
|
| 64 |
+ |
|
| 45 | 65 |
} |
| 46 | 66 |
|
| 47 | 67 |
@Override |